package dbBean;
import java.sql.*;
public class DBBean
{
	private String driverStr = "sun.jdbc.odbc.JdbcOdbcDriver";
	private String connStr = "jdbc:odbc:mydbsource";
	private Connection conn = null;
	private Statement stmt = null;

	public DBBean() 
	{
		try {
			Class.forName(driverStr); 
		}
		catch(ClassNotFoundException ex) {
			System.out.println(ex.getMessage());
		}
	}
	public void setDriverStr(String dstr)
	{
		driverStr=dstr;
	}
	public void setConnStr(String cstr)
	{
		connStr=cstr;
	}
	public ResultSet executeQuery(String sql) 
	{
		ResultSet rs = null;
		try {
			conn = DriverManager.getConnection(connStr); 
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
		} 
		catch(SQLException ex) { 
			System.out.println(ex.getMessage());
		}
		return rs;
	}
	public int executeUpdate(String sql)
	{
		int result=0;
		try{
			conn = DriverManager.getConnection(connStr);
			stmt = conn.createStatement();
			result = stmt.executeUpdate(sql);
		}
		catch(SQLException ex){
			System.out.println(ex.getMessage());
		}
		return result;
	}
	public void close()
	{
		try{
			stmt.close();
			conn.close();
		}
		catch(SQLException ex){
			System.out.println(ex.getMessage());
		}
	}
}
